package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.operator.pojo.TbBrand;
import com.dongdongshop.operator.pojo.TbBrandExample;
import com.dongdongshop.operator.service.TbBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;
import java.util.List;

@Service
@Component
public class TbBrandServiceImpl implements TbBrandService {

    @Autowired
    private DataSource dataSource;
    @Autowired
    private TbBrandMapper brandMapper;

    @Override
    public List<TbBrand> getBrand() {
        List<TbBrand> tbBrands = brandMapper.selectByExample(new TbBrandExample());
        return tbBrands;
    }

    @Override
    @Transactional
    public void addBrand(TbBrand brand) {
        brandMapper.insertSelective(brand);
    }

    @Override
    public TbBrand getBrandById(Long id) {
        TbBrand tbBrand = brandMapper.selectByPrimaryKey(id);
        return tbBrand;
    }

    @Override
    @Transactional
    public void updateBrandById(TbBrand brand) {
        brandMapper.updateByPrimaryKey(brand);
    }

    @Override
    @Transactional
    public void deleteBrandByIds(Long[] ids) {
        brandMapper.deleteBrandByIds(ids);
    }
}
